#ifndef FIRMWAREDOWNLOAD_HPP
#define FIRMWAREDOWNLOAD_HPP
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "flash.hpp"
#include "sdk_config.h"

using namespace device;

#define OTA_CHECKSUM		0x20211202

namespace ota
{
	class firmwaredownload
	{
		private:
			flash *mFirmWareDownloadFlash;    ///>下载flash 实列
			uint32_t mFirmWareDownloadState;  ///>下载状态
			uint32_t mFirmWareDownloadIndex;  ///>下载偏移
		public:
			
			typedef struct
			{
				uint32_t uiNewVersion;			///<软件新版本
				uint32_t uiOldVersion;			///<软件当前版本
				uint32_t uiLength;					///<固件程序长度
				uint32_t uiPackLength;			///<分包大小
				uint32_t uiUpdateCount;			///<单次升级次数统计
				uint32_t uiPrgCheckSum;			///<固件程序校验和
				uint32_t uiInforCheckSum;		///<信息校验和
			}FirmWareInforTPDF;						///<固件信息
			
			bool CheckSumEnable;
			FirmWareInforTPDF FirmWareInfor;
			
			firmwaredownload(flash *tResourceFlash);
			bool Start(void);
			bool Stop(void);
			bool WritePrg(uint32_t uiPackIndex, uint8_t *ucBuff, uint16_t usLen);
			bool UpDatePrgInfor(void);
			bool ReadPrgInfor(void);
			bool ReadPrgInfor(FirmWareInforTPDF *tFirmWareInfor);
			static bool PrgInforUseable(FirmWareInforTPDF *tFirmWareInfor); ///>程序信息验证
	};
}

#endif
